package auctionhausen



import java.util.Date;

import org.junit.*
import grails.test.mixin.*

@TestFor(BidController)
@Mock([Bid, Customer, Listing])
class BidControllerTests {


	def populateValidParams(params) {
		assert params != null
		params["amount"] = 36.00
		params["bidder.id"] = 1
		params["listing.id"] = 1
		params["id"] = 1
	}

	void testIndex() {
		controller.index()
		assert "/bid/list" == response.redirectedUrl
	}

	void testList() {

		def model = controller.list()

		assert model.bidInstanceList.size() == 0
		assert model.bidInstanceTotal == 0
	}

	void testCreate() {
		def model = controller.create()

		assert model.bidInstance != null
	}

	void testSave() {
		controller.bidService = [createBid : {return [hasErrors : {return true}]}];
		controller.save()

		assert model.bidInstance != null
		assert view == '/bid/create'

		response.reset()

		populateValidParams(params)
		controller.bidService = [createBid : {return [hasErrors : {return false}, id : 1]}];
		controller.save()

		assert response.redirectedUrl == '/bid/show/1'
		assert controller.flash.message != null
	}
}
